library(reshape2)
mydata <- data.frame(ID = c(1,1,2,2),Time = c(1,2,1,2),
                     X1 = c(5,3,6,2), X2 = c(6,5,1,4))
mydata
md <- melt(mydata,id = c('ID','Time'))
md
# 三种重铸形式：聚合
dcast(md,ID~variable,mean)
dcast(md,Time~variable,mean)
dcast(md,ID~Time,mean)

# 不聚合
dcast(md,ID+Time~variable)
dcast(md,ID+variable ~Time)
dcast(md,ID~variable + Time)


fruit <- c("apple", "banana", "pear", "pinapple")
str_detect(fruit, "a") # 字符串有a就行
str_detect(fruit, "^a") # 开头有a
str_detect(fruit, "a$") # 截尾有a
str_detect(fruit, "[bl]") # 字符串有b或者l
